﻿using System.Collections.Generic;
using System.Data;
using POS.BusinessEntities;

namespace POS.DataObjects
{
    public class DOEstacion: DOBase
    {
        #region Declarations

        private const string getListSP = "EstacionGetList";
        private const string saveSP = "EstacionSave";
       
        #endregion

        #region Methods: Public

        public virtual IList<BEEstacion> GetList(int empresaId, int sucursalId, string filter)
        {
            var result = new List<BEEstacion>();

            var command = Db.GetStoredProcCommand(getListSP);
            Db.AddInParameter(command, "@empresaId", DbType.Int32, empresaId);
            Db.AddInParameter(command, "@sucursalId", DbType.Int32, sucursalId);
            Db.AddInParameter(command, "@filtro", DbType.String, filter);
            var data = Db.ExecuteDataSet(command);

            if (data.Tables.Count == 1)
            {
                foreach (DataRow row in data.Tables[0].Rows)
                    result.Add(CreateEntityFromDataRow<BEEstacion>(row));
            }
            return result;
        }

        public virtual void Save(BEEstacion entity, int empresaId, int sucursalId, string user)
        {
            var command = Db.GetStoredProcCommand(saveSP);
            Db.AddInParameter(command, "@id", DbType.Int32, entity.Id);
            Db.AddInParameter(command, "@nombre", DbType.String, entity.Nombre);
            Db.AddInParameter(command, "@empresaId", DbType.Int32, empresaId);
            Db.AddInParameter(command, "@sucursalId", DbType.Int32, sucursalId);
            Db.AddInParameter(command, "@consecutivoFactura", DbType.String, entity.ConsecutivoFactura);
            Db.AddInParameter(command, "@consecutivoDevolucion", DbType.String, entity.ConsecutivoDevolucion);
            Db.AddInParameter(command, "@impresoraFacturas", DbType.String, entity.ImpresoraFacturas);
            Db.AddInParameter(command, "@impresoraDevoluciones", DbType.String, entity.ImpresoraDevoluciones);
            Db.AddInParameter(command, "@impresoraTiquetes", DbType.String, entity.ImpresoraTiquetes);
            Db.AddInParameter(command, "@user", DbType.String, user);
            Db.ExecuteNonQuery(command);
        }

        #endregion
    }
}
